var pageNum;
var arrayIds = new Array();
$(function () {
    initTime('beginTime','endTime','');

    getAgentUserList(1);
        $("body").on("ifChanged",".i-checks",function(){
        var that=$(this);
        if(that.prop("checked")){
            arrayIds.push(that.val());
        }else {
            arrayIds.splice($.inArray(that.val(), arrayIds));

        };
        //
    });


    /**
     * 查询推广员列表
     * @param pageNo
     */
    function getAgentUserList(pageNo) {
        var params = $("#search-form").serializeJSON();
        params.status=3;
        params.typeTo="open";
        params = JSON.stringify(params);
        var obj = {
            url: baseloaction + '/admin/agent/user/ajaxQueryAgentUserList',//请求URL
            contextId: 'agentUser-list-context',//响应内容页面设置内容ID
            params: params,//请求参数
            pageNo: pageNo,//页码
            pageCall: getAgentUserList, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
            selectAllId: 'all-agentUser', //全选框ID
            callback: function (pageNo) {//数据加载完成回调
                $("#count").html(total);
                pageNum = pageNo;
                setAllIds();
            }
        };
        ajaxGetListData(obj);

    }

    function setAllIds() {
        if(arrayIds.length>0){
            var obj = $('.i-checks');
            $.each(obj, function (i, item) {
                if( $.inArray($(item).val(), arrayIds)!=-1){
                    $(item).iCheck('check');
                }else{
                    $(item).iCheck('uncheck');
                }
            });
        }

    }
});
/**
 * 拼接ID串
 * @param obj
 * @returns {*}
 */
function agentIds() {
    return arrayIds.join(",");
}
